home *** CD-ROM | disk | FTP | other *** search
- Path: usenet.eel.ufl.edu!pacifier!usenet
- From: dgager@pacifier.com (Dave Gager)
- Newsgroups: comp.lang.c++
- Subject: Re: Help with cin.get()
- Date: 16 Jan 1996 04:28:31 GMT
- Organization: Pacifier Internet Server (360) 693-0325
- Message-ID: <4df9hf$fec@news.pacifier.com>
- References: <4cqbja$62n@earth.njcc.com>
- Reply-To: dgager@pacifier.com
- NNTP-Posting-Host: ip61.van2.pacifier.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.2
-
- In article <4cqbja$62n@earth.njcc.com>, chris@pluto.njcc.com says...
- >
- >I use this function to input a book title with imbedded blanks:
- >
- > void getdata()
- > {
- > cout << "Enter title: ";
- > cin.get(title, LEN);
- > cout << "Enter price: ";
- > cin >> price;
- > }
- >
- >problem is, if I execute the function more than once, it skips the title
- input
- >on the second and every subsequent execution (i.e. the line will
- resemble:
- > Enter title: Enter price:
- >never offering the oppurtunity to enter the title).
- >
- >I suspect this little "bug" arises from a subtle misuse of cin.get().
- Can
- >anyone identify it for me? This is obviously a beginner question.
- >
- >My thanks and apologies.
- >chris.
- >chris@pluto.njcc.com
-
-
- Two things come to mind without seeing the rest of the code....
-
- Number one: Your variable LEN for the max number of chars in the book
- title... if the title doesn't fill the the max number, your enter price
- will fill the remaining buffer.
-
- Number two: You need to flush out the input stream to remove any previous
- residue, and to help alleviate the problem number one above. It's been a
- while, but I think there is a clear() or flush() function to accomplish
- this. Check your compilers language reference to find out.
- Hope this helps!
- -Dave
-
- --
- -------------------------------------------------------------------------
- -----
- Pacifier Online Data Service Dialup SLIP/PPP User
- To register: (360) 693-0325 or telnet pods.pacifier.com
- -------------------------------------------------------------------------
- -----
-
-